#include "xlcd.h"
#include "delay.h"

/*******************************************************************
Function Name :         WriteCmdXLCD
Description:            This function write a command to the 
                        Instruction Register of the LCD controller.
                        The user must first check if the controller 
                        is busy or not by calling the BusyXLCD()
                        function.
Input parameters:       char cmd
Return value:           void
********************************************************************/
void WriteCmdXLCD(char cmd)
{
    RW_PIN = 0;   /* enable write */
    RS_PIN = 0;   /* select Instruction Reg */

    E_PIN = 0;
    /* configure the common data pins as output */
    TRIS_DATA_PIN_7 = 0;
    TRIS_DATA_PIN_6 = 0;
    TRIS_DATA_PIN_5 = 0;
    TRIS_DATA_PIN_4 = 0;

    DATA_PIN_7 = (unsigned int)((cmd & 0x80)>>7);
    DATA_PIN_6 = (unsigned int)((cmd & 0x40)>>6);
    DATA_PIN_5 = (unsigned int)((cmd & 0x20)>>5);
    DATA_PIN_4 = (unsigned int)((cmd & 0x10)>>4);

    DelayRSSetupTime();
    E_PIN = 1; /*Clock command in*/
    DelayEPulseWidthHigh();
    E_PIN = 0;

    DATA_PIN_7 = (unsigned int)((cmd & 0x08)>>3);
    DATA_PIN_6 = (unsigned int)((cmd & 0x04)>>2);
    DATA_PIN_5 = (unsigned int)((cmd & 0x02)>>1);
    DATA_PIN_4 = (unsigned int)((cmd & 0x01)>>0);

    DelayEPulseWidthLow();
    E_PIN = 1; /*Clock command in*/
    DelayEPulseWidthHigh();
    E_PIN = 0;

   /*configure all pins to input mode*/
    TRIS_DATA_PIN_7 = 1;
    TRIS_DATA_PIN_6 = 1;
    TRIS_DATA_PIN_5 = 1;
    TRIS_DATA_PIN_4 = 1;


}  /* end of function */

